<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    /**
     * 表名称
     * @var $table;
     */
    protected $table = 'comment';

    /**
     * 主键
     * @var $primaryKey
     */
    protected $primaryKey = 'id';

    /**
     * 时间戳   laravel ORM 自动维护数据库时间戳,用户数据结构的回滚操作,默认开启,我们禁止
     * @var bool $timestamps
     */
    public $timestamps = false;
    protected $appends = array('mobile_picture');
    /**
     * 自动填充字段
     * @var $fillable
     */
    protected $fillable = ['order_goods_id', 'user_id','label','star','add_time','content','ip_address','picture'];
    function getMobilePictureAttribute(){
        $mobile_picture_str = '';
        $picture = $this->getAttribute('picture');
        //dd($picture);
        if(!$picture){
            return null;
        }
        $picArr=explode(',',$picture);
        //dd($picArr);
        foreach ($picArr as $key=>$pic) {
            if(!$pic){
                continue;
            }
            $picString = @Picture::find($pic)->url;
            if($key==0){
                $mobile_picture_str = $picString;
            }else{

                $mobile_picture_str .= ','.$picString;
            }

        }

        return $mobile_picture_str;


    }
}
